package leetCode;

import java.util.Stack;

public class T1047 {
    public static void main(String[] args) {

    }
}

class SolutionT1047 {
    public String removeDuplicates(String s) {
        Stack<Character>stack=new Stack<>();
        char[] sChars = s.toCharArray();
        for (char sChar:sChars){
            if (!stack.isEmpty()&&stack.peek()==sChar){
                stack.pop();
            }else {
                stack.push(sChar);
            }
        }
        String ret=new String();
        while (!stack.isEmpty()){
            ret=stack.pop()+ret;
        }
        return ret;
    }
}